<div id="form"></div>
<script>
var grid;
var frm=$("#form").ajajform({
	header: "{{!Edit page template}}",
	submit: {
		url: '{{action}}',
		value: "{{!Save}}",
		ajaj: true,
		params: {mode: "save",id: '{{fields.id}}',ajaj: 1},
	},
	footerButtons: [
		{value:"{{!Add place}}", click: function() {grid.ajajform_grid("insertRow",null,{rowClass: "place",cells:["","",1,0,0,20]});}},
		{value:"{{!Delete places}}", click: function() {grid.ajajform_grid("deleteSelectedRownums");}}
	]
});
frm.ajajform("insertWidget",null,null,{
	type: "textedit",
	name: "name",
	label: "{{!Template name}}",
	not_null:1,
	width: 500,
	value: {{JSON:template.name}}
});
frm.ajajform("insertWidget",null,null,{
	type: "textedit",
	name: "code",
	label: "{{!Filename}}",
	not_null:0,
	is_code:1,
	width: 500,
	value: {{JSON:template.code}}
});
grid=frm.ajajform("insertWidget",null,null,{
	type: "grid",
	rowSelection: true,
	title: "{{!Template places}}",
	name: "places",
	post: "json",
	mode: "form-edit-full",
	rowClasses: [{
		name:"place",
		columns: [
			{name: "code", label: "Code", width: 150},
			{name: "name", label: "{{!Place name}}", width: 400},
			{name: "place_type_id", label: "{{!Place type}}", type: "select", width: 300, source: {{JSON:dictionaries.template_place_types}}},
			{name: "templatewide", label: "{{!Same on all pages}}", width: 150,type:"checkbox"},
			{name: "preprocess", label: "{{!Preprocess data}}", width: 150,type:"checkbox"},
			{name: "admin_height", label: "{{!Height}}", width: 90},
		]
	}]
});
frm.ajajform("insertWidget",null,null,{
	type: "textareaedit",
	name: "tmpltext",
	label: "{{!Template code}}",
	width: win_x()-600,
	height: 500,
	value: "{{JS:template.tmpltext}}"
});
var places={{JSON:template_places}};
for (var i=0;i<places.length;i++) {
	var pl=places[i];
	grid.ajajform_grid("insertRow",null,{rowClass: "place",cells:[pl.code,pl.name,pl.place_type_id,pl.templatewide,pl.preprocess,pl.admin_height],id:pl.id});
}
</script>
<script>
//var ta=$("#frm-tmpltext textarea")[0];
//ta.id="tmpltext-area";
//var editor = CodeMirror.fromTextArea(ta, {mode: {name: "xml", htmlMode: true}});
//editAreaLoader.init({id: "tmpltext-area",start_highlight: true,allow_resize: "both",allow_toggle: true,word_wrap: true,language: "en",syntax: "html"});

</script>

